package cn.wolfcode.wolf2w.business.controller;

import cn.wolfcode.wolf2w.business.util.SmsUtil;
import cn.wolfcode.wolf2w.common.core.domain.R;
import cn.wolfcode.wolf2w.common.core.utils.uuid.UUID;
import cn.wolfcode.wolf2w.common.redis.service.RedisService;
import cn.wolfcode.wolf2w.common.redis.util.RedisKeys;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/sms")
public class SmsController {

    @Autowired
    private RedisService redisService;

    @PostMapping("/sendVerifyCode")
    public Object sendVerifyCode(String phone) {
        Random random = new Random();
        Integer rand = random.nextInt(90000)+10000;
        String code = rand.toString();
       // SmsUtil.sendSmsAli(phone, code);
        System.err.println("验证码为："+code);
        //存储验证码到redis中
        String key = RedisKeys.VERIFY_CODE.join(phone);
        redisService.setCacheObject(key, code, RedisKeys.VERIFY_CODE.getTime(), TimeUnit.SECONDS);

        return R.ok();
    }

}
